Make locale debugging a compile-time constexpr debug instead of #ifdef. (#1011)
authorRobert Lipe <robertlipe@users.noreply.github.com>
Wed, 12 Apr 2023 22:51:17 +0000 (17:51 -0500)
committerGitHub <noreply@github.com>
Wed, 12 Apr 2023 22:51:17 +0000 (17:51 -0500)
* Make locale debugging a compile-time constexpr debug instead of #ifdef.

* Ignore *.a in git so a branch change work more effortlessly on MacOS. (Yeah, not part of this CL...)

Co-authored-by: GPSBabel <12013583+GPSBabelDeveloper@users.noreply.github.com>
.gitignore
main.cc

index a96f4c7957cdebc6b1d46debd236cce5f136dc45..3ec3a113c86ed58c98931794a3b0e5333c668220 100644 (file)
@@ -23,6 +23,7 @@
 /*.gcno
 /*.gcov
 *.o
+*.a
 .ninja_deps
 .ninja_log
 build.ninja
diff --git a/main.cc b/main.cc
index af61aa3e4f3d8d80819f2b4de3d74216663dad37..da928332eff6bf45f4020218fd184927614a2a57 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -23,8 +23,6 @@
 #include <cstdio>                     // for printf, fflush, fgetc, fprintf, stderr, stdin, stdout
 #include <cstring>                    // for strcmp
 
-#include <QByteArray>                 // for QByteArray
-#include <QChar>                      // for QChar
 #include <QCoreApplication>           // for QCoreApplication
 #include <QFile>                      // for QFile
 #include <QIODevice>                  // for QIODevice::ReadOnly
@@ -57,6 +55,8 @@
 #include "src/core/usasciicodec.h"    // for UsAsciiCodec
 #include "vecs.h"                     // for Vecs
 
+static constexpr int DEBUG_LOCALE = 0;
+
 #define MYNAME "main"
 // be careful not to advance argn passed the end of the list, i.e. ensure argn < qargs.size()
 #define FETCH_OPTARG qargs.at(argn).size() > 2 ? QString(qargs.at(argn)).remove(0,2) : qargs.size()>(argn+1) ? qargs.at(++argn) : QString()
@@ -707,9 +707,9 @@ main(int argc, char* argv[])
 #error MSVC 2015 and earlier are not supported. Please use MSVC 2017 or MSVC 2019.
 #endif
 
-#ifdef DEBUG_LOCALE
-  printf("Initial locale: %s\n",setlocale(LC_ALL, NULL));
-#endif
+  if constexpr (DEBUG_LOCALE) {
+    printf("Initial locale: %s\n",setlocale(LC_ALL, NULL));
+  }
 
   // Create a QCoreApplication object to handle application initialization.
   // In addition to being useful for argument decoding, the creation of a
@@ -724,33 +724,32 @@ main(int argc, char* argv[])
   // may result in LC_ALL being set to the native environment
   // as opposed to the initial default "C" locale.
   // This was demonstrated with Qt5 on Mac OS X.
-#ifdef DEBUG_LOCALE
-  printf("Locale after initial setup: %s\n",setlocale(LC_ALL, NULL));
-#endif
+  if constexpr (DEBUG_LOCALE) {
+    printf("Locale after initial setup: %s\n",setlocale(LC_ALL, NULL));
+  }
   // As recommended in QCoreApplication reset the locale to the default.
   // Note the documentation says to set LC_NUMERIC, but QCoreApplicationPrivate::initLocale()
   // actually sets LC_ALL.
   // Perhaps we should restore LC_ALL instead of only LC_NUMERIC.
   if (strcmp(setlocale(LC_NUMERIC,nullptr), "C") != 0) {
-#ifdef DEBUG_LOCALE
-    printf("Resetting LC_NUMERIC\n");
-#endif
+    if constexpr (DEBUG_LOCALE) {
+      printf("Resetting LC_NUMERIC\n");
+    }
     setlocale(LC_NUMERIC,"C");
-#ifdef DEBUG_LOCALE
-    printf("LC_ALL: %s\n",setlocale(LC_ALL, NULL));
-#endif
+    if constexpr (DEBUG_LOCALE) {
+      printf("LC_ALL: %s\n",setlocale(LC_ALL, NULL));
+    }
   }
   /* reset LC_TIME for strftime */
   if (strcmp(setlocale(LC_TIME,nullptr), "C") != 0) {
-#ifdef DEBUG_LOCALE
-    printf("Resetting LC_TIME\n");
-#endif
+    if constexpr (DEBUG_LOCALE) {
+      printf("Resetting LC_TIME\n");
+    }
     setlocale(LC_TIME,"C");
-#ifdef DEBUG_LOCALE
-    printf("LC_ALL: %s\n",setlocale(LC_ALL, NULL));
-#endif
+    if constexpr (DEBUG_LOCALE) {
+      printf("LC_ALL: %s\n",setlocale(LC_ALL, NULL));
+    }
   }
-
   qInstallMessageHandler(MessageHandler);
 
   (void) new gpsbabel::UsAsciiCodec(); /* make sure a US-ASCII codec is available */